{{if (!$this -> habilitation):}}
	<div class="sep"></div>
	<div class="msg msg-erreur">
		<p>
			{{=trad('Vous n\'avez pas les habilitations suffisantes pour afficher cette page.', APPLNG)}}
		</p>
	</div>
{{else:}}
	{{if($this -> erreur_table):}}
	<div class="sep"></div>
	<div class="msg msg-erreur">
		<p>
			{{=trad('La table ' . $this -> table . ' n\'est pas correctement configurée.', APPLNG)}}
		</p>
	</div>
	{{exit;}}
	{{endif;}}
	<img src="{{=URL_SITE}}?titrettf=1&txt={{=trad($this -> titre, APPLNG)}}" alt="{{=trad($this -> titre, APPLNG)}}" title="{{=trad($this -> titre, APPLNG)}}" /><p />
	{{if($this -> gridhtml["vide"]):}}
			<div class="sep"></div>
			<div class="msg msg-erreur">
				<p>
					{{if (!strlen(get_s('requete_' . $this -> table))):}}
						{{=trad('Aucun enregistrement à afficher.', APPLNG)}}
					{{else:}}
						{{=trad('Aucun enregistrement ne correspond à la requête.', APPLNG)}}
						<br >
						<a href="{{=rw($this -> page, 'table=' . $this -> table . '&delfiltre=1')}}">{{=trad('Effectuer une autre requête.', APPLNG)}}</a>
					{{endif;}}
				</p>
			</div>
		{{else:}}
		<script>
			var cle = "{{=md5(get_s('bo_user') . $this -> table . date('dmY'))}}";
			var champs = new Array();
			var champs_id = new Array();
			var champs_type = new Array();
			var champs_type_select = new Array();
			var champs_data = new Array();
			{{foreach ($this -> get_filtre as $tmpchmp):}}
				champs.push("{{=$tmpchmp['nom']}}");
				champs_id.push("{{=$tmpchmp['id']}}");
				champs_type.push("{{=$tmpchmp['type']}}");
				champs_type_select.push("{{=$tmpchmp['typeselect']}}");
				champs_data.push("{{=$tmpchmp['data']}}");
			{{endforeach;}}
			
			function addfiltre()
			{
				var index = document.getElementById('nbfiltre').value;
				document.getElementById('nbfiltre').value = parseInt(index) + 1;
				var NouvelleLigne = document.getElementById('tablefiltre').insertRow(index);
				NouvelleLigne.setAttribute('id', 'tr_filtre_' + index);
				
				var NouvelleCellule;
				
				// td1
				NouvelleCellule = NouvelleLigne.insertCell(0);
				NouvelleCellule.setAttribute('id', 'td1_filtre_' + index);
				
				var td1html = '<select id="filtre_' + index + '" onchange="champfiltre(' + index + ');"><option>{{=trad('Choisir', APPLNG)}}</option>';
				
				for (var i = 0 ; i < champs.length ; i++)
					td1html += '<option value="' + champs_id[i] + '">' + champs[i] + '</option>' + "\n";
				
				NouvelleCellule.innerHTML = td1html;
		
				// td2
				NouvelleCellule = NouvelleLigne.insertCell(1);
				NouvelleCellule.setAttribute('id', 'td2_filtre_' + index);
				var td2html = '<select id="op_' + index + '"><option value="=">&#61;</option><option value="LIKE">{{=trad('contient', APPLNG)}}</option><option value=">">&gt;</option><option value="<">&lt;</option><option value=">=">&gt;&#61;</option><option value="<=">&lt;&#61;</option><option value="<>">&#33;&#61;</option></select>';
				NouvelleCellule.innerHTML = td2html;
				
				// td3
				NouvelleCellule = NouvelleLigne.insertCell(2);
				NouvelleCellule.setAttribute('id', 'tdfiltre_' + index);
				var td3html = '';
				NouvelleCellule.innerHTML = td3html;
				
				// td4
				NouvelleCellule = NouvelleLigne.insertCell(3);
				NouvelleCellule.setAttribute('id', 'supp_' + index);
				document.getElementById('supp_'+index).style.display = 'none';
				var td4html = '<a href="#" onclick="suppfiltre(' + index + '); return false;"><img src="{{=URL_SITE}}img/delete.png" /></a>';
				NouvelleCellule.innerHTML = td4html;

			}
			
			function get_index(id)
			{
				for (var i = 0 ; i < champs_id.length ; i++)
				{
					if (champs_id[i] == id)
						return i;
				}
				return "";
			}
			
			function champfiltre(id)
			{
				var html;
				var val = $('#filtre_' + id).val();
				var index = get_index(val);
				var type = champs_type[index];
				if (type == 'select')
				{
					var type_select = champs_type_select[index];
					var data = champs_data[index];
				}
				if (type == 'input')
					html = '<input id="rec_' + id + '" size="15" />';
				else if (type == 'date')
					html = '<input id="rec_' + id + '" size="15" />&nbsp;&nbsp;&nbsp;<img style="position: relative; top: 4px; cursor: pointer;" onclick="displayCalendar(document.getElementById(\'rec_' + id + '\'),\'dd/mm/yyyy\',this);" src="{{=URL_SITE}}img/calendrier.gif" title="{{=trad('Choisir une date', APPLNG)}}" alt="{{=trad('Choisir une date', APPLNG)}}" id="imgdate_' + id + '" />';
				else if (type == 'select')
				{
					var options = '';
					if (type_select == 'vocabulaire')
					{
						var tab = data.split(';');
						for (var i = 0 ; i < tab.length ; i++)
						{
							var seg = tab[i].split('%%');
							var cle = seg[0];
							var val = seg[1];
							options += '<option value="' + cle + '">' + val + '</option>' + "\n";
						}
						html = '<select id="rec_' + id + '">' + options + '</select>';
					}
					
					else if (type_select == 'sql')
					{
						var requete = data;
						var datas = sql(requete);
						var tab = datas.split(';');
						for (var i = 0 ; i < tab.length ; i++)
						{
							var seg = tab[i].split('%%');
							var cle = seg[0];
							var val = seg[1];
							options += '<option value="' + cle + '">' + val + '</option>' + "\n";
						}
						html = '<select id="rec_' + id + '">' + options + '</select>';
					}
				}

				
				$('#tdfiltre_' + id).html(html);
				$('#supp_' + id).show();

			}
			
			function suppfiltre(id)
			{
				var del = $('#filtredel').val();
				if (del.length > 0)
					document.getElementById('filtredel').value = del + ',' + id;
				else
					document.getElementById('filtredel').value = id;
				$('#tr_filtre_' + id).hide(500);
			}
			
			function validfiltre()
			{
				var index = $('#nbfiltre').val();
				var del = $('#filtredel').val();
				
				var bad = del.split(',');
				var good = '';
				
				if (index > 1)
				{		
					for (var i = 0 ; i < index ; i++)
					{
						if (del.length > 0)
						{
							if (!in_array(i, bad))
								good += i + ',';
						}
						else
							good += i + ',';
					}
					var tab = good.split(',');
				}
				
				else
				{
					var tab = new Array();
					tab[0] = 0;
					tab[1] = 1;
				}
				
				var requete = "";		
				
				for (var i = 0 ; i < (tab.length - 1) ; i++)
				{
					var id = tab[i];
					
					var champ = $('#filtre_' + id).val();
					var op = $('#op_' + id).val();
					
					if (!document.getElementById('rec_' + id))
					{
						alert("{{=trad('Le filtrage n\'est pas correct, merci de le corriger.', APPLNG)}}");
						return false;
					}
					
					var cond = $('#rec_' + id).val();
					
					if (cond.length < 1 || cond == 'undefined')
					{
						alert("{{=trad('Le filtrage n\'est pas correct, merci de le corriger.', APPLNG)}}");
						return false;
					}
					
					requete += champ + '$$' + op + '$$' + '***' + cond + '***';
					if (i < (tab.length - 2))
						requete += '%%';
				}

				document.getElementById('requete').value = requete;
				document.getElementById('formrequete').submit();
			}
			
			function del(id, table)
			{
				if (confirm("{{=trad('Souhaitez-vous vraiment supprimer cet enregistrement ?', APPLNG)}}"))
				{
					var url = 'index.php?del=1&delid='+id+'&deltable='+table+'&delcle=' + cle;
					var methode = 'GET';
					var res = Get_HTML(url, methode);
					if (res == 'OK')
					{
						alert("{{=trad("L'enregistrement a été correctement effacé.", APPLNG)}}");
						document.location.href = document.URL;
					}
					else
					{
						alert("{{=trad('une erreur est survenue lors de l\'effacement, merci de recommencer.', APPLNG)}}");
						return false;
					}
				}
			}


		</script>
		<img alt="{{=trad('Ajouter un nouvel enregistrement')}}" title="{{=trad('Ajouter un nouvel enregistrement')}}" src="{{=URL_SITE}}img/add.png" style="position: relative; top: 5px;" />&nbsp;&nbsp;<a href="{{=rw('add', 'table=' . $this -> table)}}">{{=trad('Ajouter un nouvel enregistrement')}}</a>
		<div class="sep"></div>
		{{if (!strlen(get_s('requete_' . $this -> table))):}}
		<form id="formrequete" action="{{=URL_SITE}}" method="POST">
			<input type="hidden" value="{{=$this -> page}}" id="{{=NOMPAGE}}" name="{{=NOMPAGE}}" />
			<input type="hidden" value="{{=$this -> table}}" id="table" name="table" />
			<input type="hidden" value="1" id="delcache" name="delcache" />
			<input type="hidden" value="" name="requete" id="requete" />
		</form>

		<input id="nbfiltre" type="hidden" value="0" />
		<input id="filtredel" type="hidden" value="" />
		<input id="lastligne" type="hidden" value="0" />
		
		<span onclick="aff_filtre();" style="cursor: pointer;" id="spanfiltre"><img src="{{=URL_SITE}}img/filtrer.gif" /> <span id="titre_filtre">{{=trad('Ajouter un filtre')}}</span></span>
		<div class="sep"></div>
		<div id="filtre">
			<table id="tablefiltre">
			</table>
			<div class="sep"></div>
			<img id="addpng" style="cursor: pointer;" src="{{=URL_SITE}}img/add.png" onclick="addfiltre();" />&nbsp;&nbsp;&nbsp;<img id="okpng" style="cursor: pointer;" src="{{=URL_SITE}}img/ok.gif" onclick="validfiltre();" />
			<div class="sep"></div>
		</div>
		{{else:}}
			<img style="position: relative; top: 5px;" src="{{=URL_SITE}}img/filtredelete.png" alt="{{=trad('Supprimer le filtre actuel.', APPLNG)}}" title="{{=trad('Supprimer le filtre actuel.', APPLNG)}}" />&nbsp;&nbsp;<a href="{{=rw($this -> page, 'table=' . $this -> table . '&delfiltre=1')}}">{{=trad('Supprimer le filtre actuel', APPLNG)}}</a>
			<div class="sep"></div>
			<div class="msg msg-info">
				<p>
					<strong>{{=trad('Filtre actuel', APPLNG)}}</strong>
					<br />
					{{=aff_filtre(get_s('requete_' . $this -> table));}}
				</p>
			</div>
			<div class="sep"></div>
		{{endif;}}
		{{if($this -> gridhtml["pages"] > 1):}}
		<strong>
			{{=trad('Enregistrements', APPLNG)}} {{=($this -> gridhtml['limite'] * $this -> gridhtml['numpage']) - ($this -> gridhtml['limite'] - 1)}} {{=trad('à', APPLNG)}} {{=($this -> gridhtml['limite'] * $this -> gridhtml['numpage'])}} {{=trad('sur', APPLNG)}} {{=$this -> gridhtml['total']}}
		</strong>
		{{else:}}
		<strong>{{=$this -> gridhtml['total']}} {{if($this -> gridhtml['total'] < 2):}}{{=trad('Enregistrement', APPLNG)}}{{else:}}{{=trad('Enregistrements', APPLNG)}}{{endif;}}</strong>
		{{endif;}}
			<p />
			{{if($this -> gridhtml["pages"] > 1):}}
				<!-- Pagination !-->
				{{=GP_fonctions::pagination(array(NOMPAGE => $this -> page, 'table' => $this -> table, 'tri' => $this -> gridhtml['tri'], 'ordre' => $this -> gridhtml['ordre']), $this -> gridhtml['numpage'], $this -> gridhtml['total'], $this -> gridhtml['limite'])}}
				<p />
			{{endif;}}
			<table class="liste">
			<thead>
			<tr>
			{{foreach($this -> gridhtml['affichage'] as $champ => $nom_affiche):}}
				{{if($champ == $this -> gridhtml['tri']):}}
					{{$ordre_rw = $this -> gridhtml["autre_ordre"];}}
				{{else:}}
					{{$ordre_rw = 'ASC';}}
				{{endif;}}
				<th style="text-align: center;">{{if(in_array($champ, $this -> gridhtml['champs_tri'])):}}<a class="blanc" href="{{=rw($this -> page, 'table=' . $this -> table . '&numpage='.$this -> gridhtml['numpage'].'&tri='.$champ.'&ordre=' . $ordre_rw)}}">{{endif;}}{{=$nom_affiche}}{{if(in_array($champ, $this -> gridhtml['champs_tri'])):}}</a>{{endif;}}{{if($champ == $this -> gridhtml['tri']):}}&nbsp;&nbsp;<img src="{{=URL_SITE}}img/sort_{{=strtolower($this -> gridhtml['ordre'])}}.png" alt="{{=$this -> gridhtml['ordre']}}" title="{{=$this -> gridhtml['ordre']}}" style="position: relative; top: 3px;" />{{endif;}}</th>
			{{endforeach;}}
				<th width="100px">&nbsp;</th>
			</tr>
			</thead>
			<tbody>
			{{$i = 0;}}
			{{foreach($this -> gridhtml["res"] as $ligne):}}
			<tr class="{{if ($i++ % 2 <> 0):}}im{{endif;}}pair">
			{{foreach($this -> gridhtml['affichage'] as $champ => $nom_affiche):}}
				{{if(strlen($this -> gridhtml['php'])): 
					eval($this -> gridhtml['php']); 
				endif;}}
				{{$val_aff = (!is_utf8($ligne[$champ])) ? utf8_encode($ligne[$champ]) : $ligne[$champ];}}
				<td style="vertical-align: middle;{{if (strstr($val_aff, '<img')):}}text-align: center;{{endif;}}">{{=sl($val_aff)}}</td>
			{{endforeach;}}
				<td style="text-align: center; vertical-align: middle;">
					<a href="{{=rw('view', 'table=' . $this -> table . '&id='.$ligne[$this -> gridhtml['id']].'&cle=' . make_cle('view', $this -> table, $ligne[$this -> gridhtml['id']]))}}"><img src="{{=URL_SITE}}img/view.png" alt="{{=trad('Afficher', APPLNG)}}" title="{{=trad('Afficher', APPLNG)}}" border="0" /></a>
					&nbsp;
					<a href="{{=rw('dup', 'table=' . $this -> table . '&id='.$ligne[$this -> gridhtml['id']].'&cle=' . make_cle('dup', $this -> table, $ligne[$this -> gridhtml['id']]))}}"><img src="{{=URL_SITE}}img/grid/duplicate.png" alt="{{=trad('Dupliquer', APPLNG)}}" title="{{=trad('Dupliquer', APPLNG)}}" border="0" /></a>
					&nbsp;
					<a href="{{=rw('edit', 'table=' . $this -> table . '&id='.$ligne[$this -> gridhtml['id']].'&cle=' . make_cle('edit', $this -> table, $ligne[$this -> gridhtml['id']]))}}"><img src="{{=URL_SITE}}img/edit.png" alt="{{=trad('Editer', APPLNG)}}" title="{{=trad('Editer', APPLNG)}}" border="0" /></a>
					&nbsp;
					<img style="cursor: pointer;" onclick="del('{{=$ligne[$this -> gridhtml['id']]}}', '{{=$this -> table}}')" src="{{=URL_SITE}}img/delete.png" alt="{{=trad('Supprimer', APPLNG)}}" title="{{=trad('Supprimer', APPLNG)}}" border="0" />
				</td>
			</tr>
			{{endforeach;}}
			</tbody>
			</table>
			{{if($this -> gridhtml["pages"] > 1):}}
				<p />
				<!-- Pagination !-->
				{{=GP_fonctions::pagination(array(NOMPAGE => $this -> page, 'table' => $this -> table, 'tri' => $this -> gridhtml['tri'], 'ordre' => $this -> gridhtml['ordre']), $this -> gridhtml['numpage'], $this -> gridhtml['total'], $this -> gridhtml['limite'])}}
			{{endif;}}
		<p />
		{{if($this -> gridhtml["pages"] > 1):}}
		<strong>
			{{=trad('Enregistrements', APPLNG)}} {{=($this -> gridhtml['limite'] * $this -> gridhtml['numpage']) - ($this -> gridhtml['limite'] - 1)}} {{=trad('à', APPLNG)}} {{=($this -> gridhtml['limite'] * $this -> gridhtml['numpage'])}} {{=trad('sur', APPLNG)}} {{=$this -> gridhtml['total']}}
		</strong>
		{{else:}}
		<strong>{{=$this -> gridhtml['total']}} {{if($this -> gridhtml['total'] < 2):}}{{=trad('Enregistrement', APPLNG)}}{{else:}}{{=trad('Enregistrements', APPLNG)}}{{endif;}}</strong>
		{{endif;}}
			<div class="sep"></div>
			<div style="text-align: right">
				<u><strong>{{=trad('Exporter', APPLNG)}}</strong></u>
				&nbsp;&nbsp;&nbsp;
				<a href="{{=rw($this -> page, 'table=' . $this -> table . '&export_bo=1&type_export_bo=xls')}}"><img border="0" src="{{=URL_SITE}}/img/xls.png" title="Excel" alt="Excel" /></a>
				&nbsp;&nbsp;&nbsp;
				<a href="{{=rw($this -> page, 'table=' . $this -> table . '&export_bo=1&type_export_bo=pdf')}}"><img border="0" src="{{=URL_SITE}}/img/pdf.png" title="PDF" alt="PDF" /></a>
			</div>
			<div class="sep"></div>
			<img style="position: relative; top: 5px;" src="{{=URL_SITE}}img/back.png" alt="{{=trad('Retour', APPLNG)}}" title="{{=trad('Retour', APPLNG)}}" />&nbsp;&nbsp;<a href="{{=$this -> retour_url}}">{{=trad('Retour', APPLNG)}}</a>
	{{endif;}}
{{endif;}}